package org.eclipse.acceleo.module.sample.service;

import java.util.List;

import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Stereotype;

public class EntityService {
	public static boolean hasDefinedPrimaryKey(Class clazz) {
		boolean result = false;
		List<Property> properties = clazz.getAllAttributes();
		if (properties != null && !properties.isEmpty()) {
			for (Property property : properties) {
				Stereotype columnStereotype = StereotypeService.getStereotype(
						property, "Column");
				if (columnStereotype != null
						&& property.hasValue(columnStereotype, "primary")) {
					result = true;
					break;
				}
			}
		}
		return result;
	}
	public static boolean hasDefinedOrderedColumn(Class clazz) {
		boolean result = false;
		List<Property> properties = clazz.getAllAttributes();
		if (properties != null && !properties.isEmpty()) {
			for (Property property : properties) {
				Stereotype columnStereotype = StereotypeService.getStereotype(
						property, "Column");
				if (columnStereotype != null
						&& property.hasValue(columnStereotype, "order")) {
					result = true;
					break;
				}
			}
		}
		return result;
	}
}
